//
//  TKYTitleTextView.m
//  StationHouseHelper
//
//  Created by apple on 2018/7/30.
//  Copyright © 2018年 铁科院. All rights reserved.
//

#import "TKYTitleTextView.h"
@interface TKYTitleTextView()
@property (nonatomic, strong) UIView *bottomLineView;

@property (nonatomic, strong) NSString *placeholderStr;

@end


@implementation TKYTitleTextView
- (instancetype)initWithFrame:(CGRect)frame titleLabelText:(NSString *)titleLabelText placeholderText:(NSString *)placeholderText {
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.titleLabel];
        self.titleLabel.text = titleLabelText;
        self.placeholderStr = placeholderText;
        
        [self addSubview:self.contentLabel];
        
        
        [self addSubview:self.selectedButton];
        [self addSubview:self.bottomLineView];
        [self addSubview:self.imageV];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(kWidthScale*10);
            make.top.equalTo(self).with.offset(0);
            make.bottom.equalTo(self).with.offset(kHeightScale *0);
            make.width.mas_equalTo(kWidthScale*80);
        }];
        
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel.mas_right).with.offset(kWidthScale*0);
            make.right.equalTo(self).with.offset(-kWidthScale*35);
            make.top.equalTo(self).with.offset(0);
            make.bottom.equalTo(self).with.offset(kHeightScale *0);
            //make.height.mas_equalTo(0);
        }];
        
        [self.selectedButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel.mas_right).with.offset(kWidthScale*200);
            make.right.equalTo(self).with.offset(-kWidthScale*25);
            make.top.equalTo(self.titleLabel.mas_top);
            make.bottom.equalTo(self).with.offset(-kHeightScale *5);
            make.width.mas_equalTo(kWidthScale*60);
        }];
        
        [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).with.offset(-kWidthScale*20);
            make.top.equalTo(self).with.offset(15);
            make.height.mas_equalTo(kWidthScale*10);
            make.width.mas_equalTo(kWidthScale*10);
        }];
        
        [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(kWidthScale*10);
            make.right.equalTo(self).with.offset(-kWidthScale*10);
            make.bottom.equalTo(self).with.offset(-kHeightScale *1);
            make.height.mas_equalTo(kWidthScale*1);
        }];
    }
    return self;
}

- (UILabel *)titleLabel{
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = @"任务标题";
        _titleLabel.font = Font(12);
    }
    return _titleLabel;
}

- (UILabel *)contentLabel{
    if (_contentLabel == nil) {
        _contentLabel = [[UILabel alloc]init];
        _contentLabel.font = Font(12);
        _contentLabel.numberOfLines = 0;
        //_contentLabel.backgroundColor = [UIColor grayColor];
        _contentLabel.textAlignment = NSTextAlignmentRight;
        //_textField.text = @"13243";
    }
    return _contentLabel;
}

- (UIView *)bottomLineView{
    if (_bottomLineView == nil) {
        _bottomLineView = [[UIView alloc]init];
        _bottomLineView.backgroundColor = kMainColour;
    }
    return _bottomLineView;
}

- (UIButton *)selectedButton{
    if (_selectedButton == nil) {
        _selectedButton = [UIButton buttonWithType:UIButtonTypeCustom];
          [_selectedButton setTitle:self.placeholderStr forState:UIControlStateNormal];
        [_selectedButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        _selectedButton.titleLabel.font = Font(14);
        _selectedButton.titleLabel.textAlignment = NSTextAlignmentRight;
        [_selectedButton addTarget:self action:@selector(selectedButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        _selectedButton.backgroundColor = [UIColor clearColor];
    }
    return _selectedButton;
}

- (UIImageView *)imageV{
    if (_imageV == nil) {
        _imageV = [[UIImageView alloc]init];
        _imageV.image = [UIImage imageNamed:@"select_btn"];
    }
    return _imageV;
}

- (void)selectedButtonAction:(UIButton *)button{
    if (self.selectedButtonBlock) {
        self.selectedButtonBlock(button);
    }
}


@end
